package net.swissbite.VolumeCallPriceCalc.utils;

/**
 * Copyright (C) 2011  David Daester
 * 
 * This file is part of VolumeCallPriceCalc.
 *
 * VolumeCallPriceCalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * VolumeCallPriceCalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with VolumeCallPriceCalc.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Util methods for duration formating.
 * 
 * @author David Däster
 * 
 */
public class DurationFormater {
	/**
	 * Returns the seconds in a readable format.
	 * 
	 * @param seconds
	 *            long value of seconds.
	 * @return a String in the format H:MM:SS.
	 */
	public static String secondsToHMMSS(long seconds) {
		StringBuilder sb = new StringBuilder();
		long minutes = seconds / 60;
		long hours = minutes / 60;
		long diffMinutes = minutes - hours * 60;
		long diffSeconds = seconds - minutes * 60;
		sb.append(hours).append(":");
		if (diffMinutes < 10)
			sb.append(0);
		sb.append(diffMinutes).append(":");
		if (diffSeconds < 10)
			sb.append(0);
		sb.append(diffSeconds);
		return sb.toString();
	}
}
